package com.zoran.study.spring.validation.constraint;


import com.zoran.study.spring.validation.validator.LuhnBankCardValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * Validates bank card number using Luhn algorithm.
 *
 * @author Winter Gao
 *
 */
@Documented
@Retention(RUNTIME)
@Target({ FIELD, PARAMETER })
@Constraint(validatedBy = { LuhnBankCardValidator.class })
public @interface BankCard {

    String message() default "{geerong.validation.constraints.BankCard.message}";

    /**
     * Bank card number pattern.
     */
    String pattern() default "^[0-9]{16,}$";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

}
